package actions;

import bin.Mud;

import java.util.Random;

public class DirectionDecider {
    private Direction chosenDirection;
    private Mud mudWindow;

    public DirectionDecider(Mud mudWindow) {
        this.mudWindow = mudWindow;
    }

    public Direction getDirection() {
        String command = mudWindow.getCommand();
        if (command.equals("NORTH") || command.equals("N")) {
            chosenDirection = Direction.NORTH;
        } else if (command.equals("SOUTH") || command.equals("S")) {
            chosenDirection = Direction.SOUTH;
        } else if (command.equals("EAST") || command.equals("E")) {
            chosenDirection = Direction.EAST;
        } else if (command.equals("WEST") || command.equals("W")) {
            chosenDirection = Direction.WEST;
        } else if (command.equals("UP") || command.equals("U")) {
            chosenDirection = Direction.UP;
        } else if (command.equals("DOWN") || command.equals("D")) {
            chosenDirection = Direction.DOWN;
        }
        return chosenDirection;
    }

    public Direction getRandomDirection() {
        Direction randomDirection = null;
        Random random = new Random();
        int dirInt = random.nextInt(5);
        if (dirInt == 0) {
            randomDirection = Direction.NORTH;
        } else if (dirInt == 1) {
            randomDirection = Direction.SOUTH;
        } else if (dirInt == 2) {
            randomDirection = Direction.EAST;
        } else if (dirInt == 3) {
            randomDirection = Direction.WEST;
        } else if (dirInt == 4) {
            randomDirection = Direction.UP;
        } else if (dirInt == 5) {
            randomDirection = Direction.DOWN;
        }

        return randomDirection;
    }

    public void moveDirection() {
        mudWindow.setRoom(mudWindow.getRoom().getRoomMove(chosenDirection));
        getRoomStuff();
    }

    public void getRoomStuff() {
        mudWindow.setReturnText(mudWindow.getRoom().showItems());
        mudWindow.setReturnText(mudWindow.getRoom().showMobs());
    }

    public void moveRandom() {
        mudWindow.setRoom(mudWindow.getRoom().getRoomMove(getRandomDirection()));
        getRoomStuff();
    }
}

